package com.example.mvc.context;

import com.example.common.utils.Statistics;
import jakarta.servlet.*;
import jakarta.servlet.annotation.WebFilter;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;

/**
 * SpringMVC下，不推荐扩展{@link org.springframework.web.filter.OncePerRequestFilter}
 * 以外的过滤器
 */
@Slf4j
@WebFilter("/*") //不能用2个*!
public class MyFilter implements Filter {

    private MyFilter(){
        Statistics.logInfo(log);
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
            throws IOException, ServletException {
        Statistics.logInfo(log, "doFilter", servletRequest);
        filterChain.doFilter(servletRequest, servletResponse);
    }
}
